package demo.reflect;

public class ReflectTarget {

    ReflectTarget(String str) {
        System.out.println("默认构造函数 s = " + str);
    }

    //无参
    public ReflectTarget() {
        System.out.println("调用了公有的无参构造方法");
    }

    public ReflectTarget(char name){
        System.out.println("带有一个参数 " + name);
    }

    //多个参数
    public ReflectTarget(String name, int index){
        System.out.println("多个参数, name " + name + " index " + index);
    }

    protected ReflectTarget(boolean n){
        System.out.println("受保护的构造函数:" + n);
    }

    private ReflectTarget(int index){
        System.out.println("私有的构造函数 " + index);
    }


    //*************字段***************
    public String name;

    protected int index;

    char type;

    private String targetInfo;

    @Override
    public String toString() {
        return "ReflectTarget{" +
                "name='" + name + '\'' +
                ", index=" + index +
                ", type=" + type +
                ", targetInfo='" + targetInfo + '\'' +
                '}';
    }

    public static void main(String[] args) {
        ReflectTarget reflectTarget = new ReflectTarget();
        //第一种方法获取class对象
        Class reflectTargetClass1 = reflectTarget.getClass();
        System.out.println("1 " + reflectTargetClass1.getName());
        //第二种
        Class reflectTargetClass2 = ReflectTarget.class;
        System.out.println("2 " + reflectTargetClass2.getName());
        //判断是否是同一个class对象
        System.out.println(reflectTargetClass1 == reflectTargetClass2);
        try {
           Class reflectTargetClass3 = Class.forName("demo.reflect.ReflectTarget");
           System.out.println(reflectTargetClass3.getName());
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        }
    }

}
